package com.wm.wmim.connect.center.rpc.impl;

import com.wm.wmim.common.dto.RpcRespDTO;
import com.wm.wmim.common.utils.RpcRespUtils;
import com.wm.wmim.connect.center.api.bo.req.OnMessageReqBO;
import com.wm.wmim.connect.sdk.onmessage.bo.resp.SendMessageCommonRespBO;
import com.wm.wmim.connect.center.api.rpc.ConnectOnMessageRpcService;
import com.wm.wmim.connect.sdk.onmessage.rpc.OnMessageRpcService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.annotation.DubboService;

/**
 * @author weiming
 * @date 2025/6/11 18:03
 * @description
 */
@Slf4j
@DubboService(version = "1.0.0")
public class ConnectOnMessageRpcServiceImpl implements ConnectOnMessageRpcService {
    @Override
    public RpcRespDTO<SendMessageCommonRespBO> onMessage(OnMessageReqBO reqBO) {
        // TODO RPC Service 工厂
        ReferenceConfig<OnMessageRpcService> rf = new ReferenceConfig<OnMessageRpcService>();
        rf.setInterface(OnMessageRpcService.class);
        rf.setVersion("1.0.0");
        rf.setCheck(false);
        rf.setGroup(reqBO.getBusinessScene());
        OnMessageRpcService onMessageRpcService = rf.get();
        log.info("[OnMessageRpcInvokeService] 接收消息 onMessage start reqBO={}", reqBO);
        RpcRespDTO<SendMessageCommonRespBO> onMessage = onMessageRpcService.onMessage(reqBO.getAttributes(), reqBO.getMessage());
        log.info("[OnMessageRpcInvokeService] 接收消息 onMessage end reqBO={}, result={}", reqBO, onMessage);
        SendMessageCommonRespBO data = RpcRespUtils.getData(onMessage);
        return RpcRespDTO.buildSuccess(data);
    }
}
